package com.wolf.etl.vo;

import com.wolf.exception.WolfException;
import com.wolf.provider.util.StringUtils;
import com.wolf.vo.KeyValuePair;

/**
 * @author sdyang
 * @date 2019/10/7 11:41
 **/
public  class WriteBack {

    private String extractFlag;
    private String writeBackFlag;
    private String writeBackFailMsg;
    private String writeBackTime;
    private String extractFlagValue;
    private String writeBackFlagValue;
    private String writeBackFailMsgValue;
    private String writeBackTimeValue;

    public String getExtractFlag() {
        return extractFlag;
    }

    public void setExtractFlag(String extractFlag) {
        this.extractFlag = extractFlag;
    }

    public String getWriteBackFlag() {
        return writeBackFlag;
    }

    public void setWriteBackFlag(String writeBackFlag) {
        this.writeBackFlag = writeBackFlag;
    }

    public String getWriteBackFailMsg() {
        return writeBackFailMsg;
    }

    public void setWriteBackFailMsg(String writeBackFailMsg) {
        this.writeBackFailMsg = writeBackFailMsg;
    }

    public String getWriteBackTime() {
        return writeBackTime;
    }

    public void setWriteBackTime(String writeBackTime) {
        this.writeBackTime = writeBackTime;
    }

    public String getExtractFlagValue() {
        return extractFlagValue;
    }

    public void setExtractFlagValue(String extractFlagValue) {
        this.extractFlagValue = extractFlagValue;
    }

    public String getWriteBackFlagValue() {
        return writeBackFlagValue;
    }

    public void setWriteBackFlagValue(String writeBackFlagValue) {
        this.writeBackFlagValue = writeBackFlagValue;
    }

    public String getWriteBackFailMsgValue() {
        return writeBackFailMsgValue;
    }

    public void setWriteBackFailMsgValue(String writeBackFailMsgValue) {
        this.writeBackFailMsgValue = writeBackFailMsgValue;
    }

    public String getWriteBackTimeValue() {
        return writeBackTimeValue;
    }

    public void setWriteBackTimeValue(String writeBackTimeValue) {
        this.writeBackTimeValue = writeBackTimeValue;
    }

    public void check() {
        String info = "The %s attribute of WriteBack is empty.";
        if (StringUtils.isEmpty(extractFlag)) {
            throw new WolfException(String.format(info, "extractFlag"));
        }

        if (StringUtils.isEmpty(writeBackFlag)) {
            throw new WolfException(String.format(info, "writeBackFlag"));
        }

        if (StringUtils.isEmpty(writeBackFailMsg)) {
            throw new WolfException(String.format(info, "writeBackFailMsg"));
        }

        if (StringUtils.isEmpty(writeBackTime)) {
            throw new WolfException(String.format(info, "writeBackTime"));
        }
    }

    public KeyValuePair getExtractAttrKeyValuePair() {
        KeyValuePair kvp = new KeyValuePair();
        kvp.setKey(this.getExtractFlag());
        kvp.setValue(this.getExtractFlagValue());
        return kvp;
    }

    public KeyValuePair[] getSuccAttrKeyValuePairs() {
        KeyValuePair[] kvps = new KeyValuePair[3];
        KeyValuePair kvp = new KeyValuePair();
        kvp.setKey(this.getWriteBackFlag());
        kvp.setValue(this.getWriteBackFlagValue());
        kvps[0] = kvp;
        kvp.setKey(this.getWriteBackTime());
        kvp.setValue(this.getWriteBackTimeValue());
        kvps[1] = kvp;
        kvp.setKey(this.getWriteBackFailMsg());
        kvp.setValue(this.getWriteBackFailMsgValue());
        kvps[2] = kvp;
        return kvps;
    }

    public KeyValuePair[] getFailAttrKeyValuePairs() {
        KeyValuePair[] kvps = new KeyValuePair[3];
        KeyValuePair kvp = new KeyValuePair();
        kvp.setKey(this.getWriteBackFlag());
        kvp.setValue(this.getWriteBackFlagValue());
        kvps[0] = kvp;
        kvp.setKey(this.getWriteBackTime());
        kvp.setValue(this.getWriteBackTimeValue());
        kvps[1] = kvp;
        return kvps;
    }
}
